package com.lbc.recursion;

public class RecursionTest {

    public static void main(String[] args) {
        // 打印问题
        print(4);
        print2(4);
        // 阶乘问题
        int n = 5;
        System.out.printf("%d! = %d \n", n, factorial(n));
    }

    public static void print(int n) {
        if (n > 2) {
            print(n - 1);
        }
        System.out.println("n1=" + n);
    }
    public static void print2(int n) {
        if (n > 2) {
            print2(n - 1);
        } else {
            System.out.println("n2=" + n);
        }
    }

    public static int factorial(int n) {
        if (n == 1) {
            return 1;
        } else {
            return factorial(n - 1) * n;
        }
    }

}
